﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;
 
namespace HZ.Supervise.Web.Secondphase
{
    public partial class ReportFristLevelList : BasePage
    {
        private DataTable dtCom;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Databind();               
            }
        }
        public void Databind()
        {
            int t = 0;

            HZ.Supervise.IBLL.IExecuteContext ie = HZ.Supervise.BLLFactory.ExecuteContext();
            ie.QueryObject = new HZ.Supervise.Model.QueryObject()
            {
                GroupField =  GroupByField .HospitalID | GroupByField.SortSource,
                Query = (SuperviseQuery)ViewState["query"],
                GroupSelectField = GroupFields.PurchaseAmountTotal| GroupFields.PurchaseCountTotal| GroupFields.WareHouseAmountTotal|GroupFields.WareHouseCountTotal|  GroupFields.WareHouseRate    ,
                SortField = "HospitalID ASC" 
            };//todo:绑定排序字段

            dtCom = ie.ExecutePage(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
            AspNetPager1.RecordCount = t;
            gvwProcureCatalog.PageSize = AspNetPager1.PageSize;
            gvwProcureCatalog.AutoGenerateColumns = false;
        
            gvwProcureCatalog.DataSource = dtCom;           
            gvwProcureCatalog.DataBind();

            //合并
            for (int j = 0; j < gvwProcureCatalog.Rows.Count; j++)
            {
                //防止超出索引
                if(j<(gvwProcureCatalog.Rows.Count-1))
                {
                    if (gvwProcureCatalog.Rows[j].Cells[0].Text.Trim() == gvwProcureCatalog.Rows[j + 1].Cells[0].Text.Trim())
                    {
                        gvwProcureCatalog.Rows[j].Cells[0].RowSpan = 2;
                        gvwProcureCatalog.Rows[j + 1].Cells[0].Visible = false;
                        j++;
                    }
                    else
                    {
                        continue;
                    }
                }             
               
            }
        }
        protected void gvwProcureCatalog_RowCreated(object sender, GridViewRowEventArgs e)
        {
        
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {

        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            Databind();
        }

        protected void lbnSwitch_Click(object sender, EventArgs e)
        {

        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {

        }
        protected void lbtnSee_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 行绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwProcureCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
        }
    }
}
